import spring.framework.beans.BeansException;
import spring.framework.beans.factory.config.BeanPostProcessor;

/**
 * @author fun.pengzh
 * @class PACKAGE_NAME.MyBeanPostProcessor
 * @desc
 * @since 2021-09-30
 */
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println(" 执行PostProcessor 前");
        if ("userService".equals(beanName)) {
            UserService userService = (UserService) bean;
            userService.setLocation("改为：广州");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println(" 执行PostProcessor 后");
        if ("userService".equals(beanName)) {
            UserService userService = (UserService) bean;
            userService.setLocation("改为：广州 白云区");
        }
        return bean;
    }
}
